//package com.heima.article.listener;
//
//import com.alibaba.fastjson.JSON;
//import com.heima.article.service.ApArticleConfigService;
//import com.heima.article.service.ApArticleService;
//import com.heima.common.constants.ArticleConstants;
//import com.heima.common.constants.WmNewsMessageConstants;
//import com.heima.model.article.pojos.ApArticle;
//import com.heima.model.user.dtos.LikesBehaviorDto;
//import com.heima.model.user.dtos.UnLikesBehaviorDto;
//import com.heima.model.user.dtos.readBehaviorDto;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.kafka.annotation.KafkaListener;
//import org.springframework.stereotype.Component;
//
//import java.util.Map;
//
//@Component
//@Slf4j
//public class XWListener {
//    @Autowired
//    private ApArticleService apArticleService;
//
//    /**
//     * 文章用户行为数据更新
//     *
//     * @param message
//     */
//    @KafkaListener(topics = ArticleConstants.XW_XW)
//    public void articleYhxw(String message) {
//        if (!StringUtils.isEmpty(message)) {
//            Object parseObject = JSON.parseObject(message, Object.class);
//            //点赞数据校验
//            extracted(message, parseObject);
//        }
//    }
//
//    private void extracted(String message, Object parseObject) {
//        //点赞
//        if (parseObject instanceof LikesBehaviorDto) {
//
//            LikesBehaviorDto likesBehaviorDto = JSON.parseObject(message, LikesBehaviorDto.class);
//
//            ApArticle apArticle = apArticleService.getById(likesBehaviorDto.getArticleId());
//
//            if (apArticle != null) {
//                if (apArticle.getLikes() == null) {
//                    apArticle.setLikes(0);
//                }
//                if (likesBehaviorDto.getOperation() == 0) {
//                    apArticle.setLikes(apArticle.getLikes() + 1);
//                } else if (likesBehaviorDto.getOperation() == 1) {
//                    apArticle.setLikes(apArticle.getLikes() - 1);
//                }
//                apArticleService.updateById(apArticle);
//                log.info("点赞数据更新");
//            }
//        }
//    }
//}
